import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Leetcode82 {
    public static void main(String[] args) {
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list, 1, 1, 1, 2, 3);
        ListNode origin = new ListNode();
        ListNode.createNode(origin, list);
        ListNode r = deleteDuplicates(origin);
        System.out.println(r);
    }

    public static ListNode deleteDuplicates(ListNode head) {
        ListNode cpHead = new ListNode(0, head);
        ListNode slow = cpHead;
        while (slow.next != null && slow.next.next != null) {
            if (slow.next.val == slow.next.next.val) {
                int x = slow.next.val;
                while (slow.next != null && slow.next.val == x) {
                    slow.next = slow.next.next;
                }
            } else {
                slow = slow.next;
            }
        }

        return cpHead.next;
    }
}

